<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
 <link href="${pageContext.request.contextPath}/assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css"/>       
        <link href="${pageContext.request.contextPath}/assets/css/codemirror.css" rel="stylesheet" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/ace.min.css" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/font/css/font-awesome.min.css" />
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
		<script src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
        <script src="${pageContext.request.contextPath}/assets/js/bootstrap.min.js"></script>
		<script src="${pageContext.request.contextPath}/assets/js/typeahead-bs2.min.js"></script>           	
		<script src="${pageContext.request.contextPath}/assets/js/jquery.dataTables.min.js"></script>
		<script src="${pageContext.request.contextPath}/assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="${pageContext.request.contextPath}/assets/layer/layer.js" type="text/javascript" ></script>          
        <script src="${pageContext.request.contextPath}/assets/laydate/laydate.js" type="text/javascript"></script>
<title>留言</title>

<script type="text/javascript">
		function submitForm()
		{
			document.getElementById("myForm").submit();
		}
		
		$(function(){
			
			 $("input[name='typeId']").click(function(){
		            $("#checkAll").prop("checked",$("input[name='typeId']").length == $("input[name='typeId']:checked").length ? true : false);
		        });
			
			$("#checkAll").click(
			  function(){
			   $("input[name='typeId']").prop("checked",this.checked);
			  }
			);
			
			//批量删除
			$("#deleteByGroup").click(function(){
				var typeId="";
				var judgement=false;
				if($("input[name='typeId']:checked").length)
					{
						layer.confirm('确认要删除吗？',function(index){
							$("input[name='typeId']:checked").each(function(){
								judgement=false;
								if(parseInt($(this).parents("tr").find(".opinionSize").html())!=0)
								{
								 	layer.alert("所选留言中存在回复不为0的记录，请重新选择",{
						               title: '提示框',				
									icon:1,		
									  });
									return false;
								}
								else
								{
									judgement=true;
									typeId=typeId+$(this).parents("tr").find(".type_id").html()+";";
								}
							});
							if(judgement){
								$("#del_list").val(typeId);
								$("#delopr").val("del");
								//alert($("#del_list").val());
								//alert($("#delopr").val());
								$("#delForm").submit();
							}
							layer.close(index);	
						});
					}
				else
					{
					 layer.alert("你未选中任何项",{
			               title: '提示框',				
						icon:1,		
						  });
					}
				//alert(typeId);
			});
		});
		
		function checkMsg()
		{
			if($("#updateopinion").length>0)
			{
				  layer.alert($("#updateopinion").html(),{
	               title: '提示框',				
				icon:1,		
				  });
			}
		}
		
	</script>


</head>

<body onload="checkMsg();">
<div class="margin clearfix">
 <div class="Guestbook_style">
    <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:ovid()" class="btn btn-danger" id="deleteByGroup" ><i class="fa fa-trash"></i>&nbsp;批量删除</a>
        <a href="opinionServlet?readornot=yes" class="btn btn-sm btn-primary"><i class="fa fa-check"></i>&nbsp;已回复</a>
        <a href="opinionServlet?readornot=no" class="btn btn-yellow"><i class="fa fa-times"></i>&nbsp;未回复</a>
        <a href="opinionServlet?opr=list" class="btn btn-sm btn-primary"><i class="fa fa-check"></i>&nbsp;全部</a>
       </span>
       <span class="r_f">共：<b>${opinionlist.size() }</b>条记录</span>
     </div>
    <!--留言列表-->
    <div class="Guestbook_list">
      <table class="table table-striped table-bordered table-hover" id="sample-table">
      <thead>
		 <tr>
          <th width="25"><label><input type="checkbox" class="ace" id="checkAll" /><span class="lbl" ></span></label></th>
          <th width="80">ID</th>
          <th width="150px">用户名</th>
          <th width="">留言内容</th>
          <th width="100px">回复数</th>
          <th width="200px">时间</th>
          <th width="70">状态</th>                
          <th width="250">操作</th>
          </tr>
      </thead>
	<tbody>
		 <c:if test="${opinionlist!= null && opinionlist.size() > 0}">
          	<c:forEach items="${opinionlist }" var="opinion">
          	<tr>
     			<td><label><input type="checkbox" class="ace" name="typeId"  /><span class="lbl"></span></label></td>
         		<td class="type_id">${opinion.opinion_id }</td>
         		<td class="opinion_customer">
         		<span id="cusinfo1" style="display:none;">${opinion.customer.customer_id }</span>
         		<span id="cusinfo2" style="display:none;">${opinion.customer.customer_name }</span>
         		<span id="cusinfo3" style="display:none;">${opinion.customer.eMail }</span>
         		<span id="cusinfo4" style="display:none;">${opinion.customer.telephone }</span>
         		<span id="cusinfo5" style="display:none;">${opinion.customer.realName }</span>
         		<span id="cusinfo6" style="display:none;">${opinion.customer.address }</span>
         		<span id="cusinfo7" style="display:none;">${opinion.customer.credit }</span>
         		<span id="cusinfo8" style="display:none;">${opinion.customer.assetLv.assetLv_name }</span>
         		<u style="cursor:pointer"  class="text-primary" onclick="member_show(this)">${opinion.customer.customer_name }</u>
         		</td>
          		<td class="text-l">
          		<a href="javascript:;" onclick="Guestbook_iew(this,'12')">${opinion.details }</a>
          		</td>
          		<td class="opinionSize">${opinion.size }</td>
          		<td>${opinion.start_date }</td>
          		<td class="td-status"><span class="label label-success radius">未锁定</span></td>
         		<td class="td-manage">
           		<a onclick="member_stop(this,'10001')"  href="javascript:;" title="未锁定"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>   
        		<a  href="replyServlet?opinion_id=${opinion.opinion_id }" title="查看回复"   class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>      
        		<a  href="javascript:;"  onclick="member_del(this)" title="删除" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>
          		</td>
        	</tr> 
          	</c:forEach>
         </c:if> 
        </tbody>
      </table>
    </div>
 </div>
</div>

<!--操作信息-->
<div style="display: none">
	<c:if test="${sessionScope.excuteMsg_opinion!=null&&sessionScope.excuteMsg_opinion.length()>0 }"><span id="updateopinion">${sessionScope.excuteMsg_opinion }</span></c:if>
</div>

<!--批量删除提交-->
<div style="display: none">
	<form action="opinionServlet" method="post" id="delForm">
		<input type="hidden" name="opr" id="delopr" />
		<input type="text" id="del_list" name="del_list" />
	</form>
</div>

<!--单个删除提交-->
<div style="display: none">
	<form action="opinionServlet" method="post" id="delBySingle">
		<input type="hidden" name="opr" value="del" />
		<input type="hidden" name="opinion_id" id="delsingleId" />
	</form>
</div>

<!--客户详情-->
<div id="cusdetails" style="display:none">
<div class="member_show" >
<div class="member_jbxx clearfix" >
<img class="img" src="${pageContext.request.contextPath}/images/user.png" />
  <dl  class="right_xxln">
  <dt><span class="cusinfo2"></span></dt>
  <dd class="" style="margin-left:0">这家伙很懒，什么也没有留下</dd>
  </dl>
</div>
<div class="member_content">
  <ul>
   <li><label class="label_name">会员号：</label><span class="cusinfo1"></span></li>
   <li><label class="label_name">邮箱：</label><span class="cusinfo3"></span></li>
   <li><label class="label_name">手机：</label><span class="cusinfo4"></span></li>
   <li><label class="label_name">真实姓名：</label><span class="cusinfo5"></span></li>
   <li><label class="label_name">地址：</label><span class="cusinfo6"></span></li>
   <li><label class="label_name">信用度：</label><span class="cusinfo7"></span></li>
   <li><label class="label_name">资产等级：</label><span class="cusinfo8"></span></li>
   
  </ul>
</div>
</div>
</div>



<!--留言详细&&添加回复-->
<div id="Guestbook" style="display:none">
<form action="replyServlet" method="post" id="addForm">
<input type="hidden" name="opr" />
<input type="hidden" name="opinion_id" id="opinion_id" />
<input type="hidden" name="admin_id" id="3" />
 <div class="content_style">
  <div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1">留言用户 </label>
       <div class="col-sm-9" id="opinion_customer"></div>
	</div>
   <div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 留言内容 </label>
       <div class="col-sm-9" id="opinion_content"></div>
	</div>
    <div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1">是否回复 </label>
       <div class="col-sm-9">
       <label><input name="checkbox" type="checkbox" class="ace" id="checkbox" /><span class="lbl"> 回复</span></label>
       <div class="Reply_style">
          <textarea id="details" name="details" class="form-control" id="form_textarea" placeholder="" onkeyup="checkLength(this);"></textarea>
          <span class="wordage">剩余字数：<span id="sy" style="color:Red;">200</span>字</span>
       </div>
       </div>
	</div>
 </div>
   </form>
</div>
</body>
</html>
<script type="text/javascript">
 
/*留言-删除*/
function member_del(obj){
	layer.confirm('确认要删除吗？',function(index){
		if(parseInt($(obj).parents("tr").find(".opinionSize").html())!=0)
		{
			 layer.alert("该留言存在回复，无法删除",{
	               title: '提示框',				
					icon:0,								
	         }); 
		}
		else
		{
			$("#delsingleId").val($(obj).parents("tr").find(".type_id").html());
			$("#delBySingle").submit();
		}
		layer.close(index);	
	});
}

/*留言-锁定*/
function member_stop(obj,id){
	layer.confirm('确认要锁定吗？',function(index){
		$(obj).parents("tr").find(".ace").prop("checked",false).attr("disabled","disabled");
		$(obj).next().remove();
		$(obj).next().remove();
		$(obj).after('<a title="查看回复" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a> <a title="删除" href="javascript:;"  class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,id)" href="javascript:;" title="解锁"><i class="fa fa-check  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已锁定</span>');
		//var $aa=$($(obj).parents("td"));
		$(obj).remove();
		//alert($aa.html());
		layer.msg('已锁定!',{icon: 5,time:1000});
	});
}
//<a title="编辑" onclick="member_edit('550')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a> 
/*留言-解锁*/
function member_start(obj,id){
	layer.confirm('确认要解锁吗？',function(index){
		$(obj).parents("tr").find(".ace").removeAttr("disabled");
		$(obj).next().remove();
		$(obj).next().remove();
		$(obj).after('<a title="查看回复" href="replyServlet?opinion_id='+$(obj).parents("tr").find(".type_id").html()+'"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a> <a title="删除"  href="javascript:;"  onclick="member_del(this)" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,id)" href="javascript:;" title="锁定"><i class="fa fa-check  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已解锁</span>');
		//var $aa=$($(obj).parents("td"));
		$(obj).remove();
		//alert($aa.html());
		layer.msg('已解锁!',{icon: 6,time:1000});
	});
}



/*checkbox激发事件*/
$('#checkbox').on('click',function(){
	if($('input[name="checkbox"]').prop("checked")){
		 $('.Reply_style').css('display','block');
		}
	else{
		
		 $('.Reply_style').css('display','none');
		}	
	});
	
/*留言查看&&回复*/
function Guestbook_iew(obj,id){
	$("input[name='opr']").val("add");
	$("#opinion_customer").html($(obj).parents("tr").find(".opinion_customer").html());
	$("#opinion_content").html($(obj).parents("tr").find(".text-l").text());
	$("#opinion_id").val($(obj).parents("tr").find(".type_id").html());
	var index = layer.open({
        type: 1,     
        title: '留言信息',
		maxmin: true, 
		shadeClose:false,
        area : ['600px' , ''],
        content:$('#Guestbook'),
		btn:['确定','取消'],
		yes: function(index, layero){		 
		  if($("#checkbox").prop("checked")){			 
			 if($('.form-control').val()==""){
				layer.alert('回复内容不能为空！',{
               title: '提示框',				
			  icon:0,		
			  }); 
			 }else{			
			      layer.alert('确定回复该内容？',{
				   title: '提示框',				
				   icon:0,	
				   btn:['确定','取消'],	
				   yes: function(index){
					   $("#addForm").submit();
					     layer.closeAll();
					   }
				  }); 		  
		   }			
	      }else{			
			 layer.alert('是否要取消回复！',{
               title: '提示框',				
			icon:0,		
			  }); 
			  layer.close(index);      		  
		  }
	   }
	});	
};

/*用户详情*/
function member_show(obj){
	$("#cusdetails").find(".cusinfo1").html($(obj).parent("td").find("#cusinfo1").html());
	$("#cusdetails").find(".cusinfo1").html($(obj).parent("td").find("#cusinfo1").html());
	$("#cusdetails").find(".cusinfo2").html($(obj).parent("td").find("#cusinfo2").html());
	$("#cusdetails").find(".cusinfo3").html($(obj).parent("td").find("#cusinfo3").html());
	$("#cusdetails").find(".cusinfo4").html($(obj).parent("td").find("#cusinfo4").html());
	$("#cusdetails").find(".cusinfo5").html($(obj).parent("td").find("#cusinfo5").html());
	$("#cusdetails").find(".cusinfo6").html($(obj).parent("td").find("#cusinfo6").html());
	$("#cusdetails").find(".cusinfo7").html($(obj).parent("td").find("#cusinfo7").html());
	$("#cusdetails").find(".cusinfo8").html($(obj).parent("td").find("#cusinfo8").html());
	var index = layer.open({
        type: 1,     
        title: '留言信息',
		maxmin: true, 
		shadeClose:false,
        area : ['600px' , ''],
        content:$('#cusdetails'),
		btn:['确定','取消'],
		yes: function(index, layero){
			  layer.close(index);      		  
		  
	   }
	});	
};


	/*字数限制*/
function checkLength(which) {
	var maxChars = 200; //
	if(which.value.length > maxChars){
	   layer.open({
	   icon:2,
	   title:'提示框',
	   content:'您输入的字数超过限制!',	
    });
		// 超过限制的字数了就将 文本框中的内容按规定的字数 截取
		which.value = which.value.substring(0,maxChars);
		return false;
	}else{
		var curr = maxChars - which.value.length; //250 减去 当前输入的
		document.getElementById("sy").innerHTML = curr.toString();
		return true;
	}
};
</script>
<script type="text/javascript">
jQuery(function($) {
var oTable1 = $('#sample-table').dataTable( {
"aaSorting": [[ 1, "desc" ]],//默认第几个排序
"bStateSave": true,//状态保存
"aoColumnDefs": [
  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
  {"orderable":false,"aTargets":[0,6,7]}// 制定列不参与排序
] } );
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
				
		});	
		$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table')
			var off1 = $parent.offset();
			var w1 = $parent.width();
	
			var off2 = $source.offset();
			var w2 = $source.width();
	
			if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
			return 'left';
		}
	});
</script>
